package com.example.bookdemo.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@Aspect
public class TimeRecordAspect {
    @Around("execution(* com.example.bookdemo.controller.*.*(..))")
    public Object timeRecord(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("表示了对所有的Controller进行生效");
        long start = System.currentTimeMillis();
        Object result = joinPoint.proceed();
        long end = System.currentTimeMillis();
        log.info(joinPoint.getSignature()+"耗时:"+(end-start));
        return result;
    }

    @Before("execution(* com.example.bookdemo.controller.*.*(..))")
    public void dobefore(){
        log.info("执行before");
    }

    @After("execution(* com.example.bookdemo.controller.*.*(..))")
    public void doAfter(){
        log.info("执行After");
    }

    @AfterReturning("execution(* com.example.bookdemo.controller.*.*(..))")
    public void doAfterReturning(){
        log.info("执行AfterReturning");
    }

    @AfterThrowing("execution(* com.example.bookdemo.controller.*.*(..))")
    public void AfterThrowing(){
        log.info("执行AfterThrowing");
    }
}
